package com.base.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置
 * @author gxd
 * @since 2025/6/8
 */
@Configuration
public class RabbitMQConfig {
    // 交换机名
    public static final String EXCHANGE_NAME = "xinchuang_test";
    // 队列名
    public static final String QUEUE_NAME = " xinchuang_one";
    // 路由键名
    public static final String ROUTE_KEY_NAME = "xinchuang.to.mybatisplus.#";

    // 交换机
    @Bean("testExchange")
    public Exchange testExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    // 队列
    @Bean("testQueue")
    public Queue testQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    // 队列和交换机绑定
    @Bean
    public Binding bindQueueExchange(@Qualifier("testQueue") Queue queue, @Qualifier("testExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTE_KEY_NAME).noargs();
    }
}
